package com.jlb.base.ctrl;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.exceptions.BaseException;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 账户 控制器
 *
 * @author pi-top
 */
@RestController
@RequestMapping("/reg")
@Slf4j
@Api(value = "账户控制器", description = "账户控制器")
public class RegCtrl {
    @Resource
    private UserSV userSV;


    /**
     * 注册账户
     *
     * @param account          账户
     * @param realName         真实姓名
     * @param password         密码
     * @param pinPassword      支付密码
     * @param phone            手机号
     * @param referenceAccount 推荐人账户
     * @return
     */
    @ApiOperation(value = "注册账户", notes = "注册账户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", required = true, dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "realName", value = "真实姓名", required = true, dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "pinPassword", value = "支付密码", required = true, dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "referenceAccount", value = "推荐人账户", required = true, dataType = "java.lang.String", paramType = "query")
    })
    @PostMapping(value = "/user/reg")
    @ResponseBody
    public BeanRet reg(String account, String realName, String password, String pinPassword, String phone, String referenceAccount) {
        if (StringUtils.isBlank(account) || StringUtils.isBlank(realName)
                || StringUtils.isBlank(password) || StringUtils.isBlank(pinPassword)
                || StringUtils.isBlank(phone) || StringUtils.isBlank(referenceAccount)) {
            return BeanRet.create();
        }
        userSV.reg(account, realName, password, pinPassword, phone, referenceAccount);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success);
    }

}
